//
//  BaseNavigationController.m
//  zaipin
//
//  Created by whj on 16/10/8.
//  Copyright © 2016年 master. All rights reserved.
//

#import "BaseNavigationController.h"

@interface BaseNavigationController ()<UIGestureRecognizerDelegate>

@end

@implementation BaseNavigationController


/**
 *  系统在第一次使用这个类的时候调用(1个类只会调用一次)--合适的代码放在合适的地方。=
 */
+(void)initialize{
    //修改 导航条的样式 统一修改 只修改一次 --合适的代码要放在合适的位置
    UINavigationBar *navBar = [UINavigationBar appearance];
    [navBar setBackgroundImage:[UIImage imageNamed:@"navigationimage"] forBarMetrics:UIBarMetricsDefault];
    //iOS7 中返回按钮的颜色 iOS7 之前是导航条背景。
    //navBar.tintColor = [UIColor whiteColor];
//    navBar.translucent = NO;
    //修改导航条的背景颜色
    // navBar.barTintColor = [UIColor orangeColor];
    //导航条的 tittle的 样式设置 。
    navBar.titleTextAttributes = @{
                                   NSFontAttributeName: [UIFont boldSystemFontOfSize:18],
                                   NSForegroundColorAttributeName:[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1],
                                   };
    
    
    
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    //自定义Navigation 导航栏 右滑返回失效解决方法
    self.navigationController.interactivePopGestureRecognizer.delegate =self;
    //当使用这个属性的时候 ，控制器的View是从导航栏的下面开始的。但是如果隐藏了导航栏，tableview的Frame是占据整个屏幕的。
    self.edgesForExtendedLayout = UIRectEdgeNone;
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
        
        UIButton * backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [backButton setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal
         ];
//        backButton.backgroundColor = PurpleColor;
        CGFloat btnWidth = 50;
        backButton.frame = CGRectMake(0, 0, btnWidth, 44);
        backButton.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
        [backButton addTarget:self action:@selector(bsBackAction) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem * leftItem = [[UIBarButtonItem alloc]initWithCustomView:backButton];
        
        // 设置导航栏按钮
        viewController.navigationItem.leftBarButtonItem = leftItem;
    }
    [super pushViewController:viewController animated:animated];
}
- (void)bsBackAction
{
    [self popViewControllerAnimated:YES];
}


@end
